package com.jindy.module.oaReceiveApproval.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaDepartApproval.controller.SyOaDepartController;
import com.jindy.module.oaDepartApproval.domain.SyOaDepart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaReceiveApproval.domain.SyOaReceive;
import com.jindy.module.oaReceiveApproval.service.ISyOaReceiveService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 招待审批Controller
 * 
 * @author jindy
 * @date 2023-06-01
 */
@RestController
@RequestMapping("/module/oaReceiveApproval")
public class SyOaReceiveController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaReceiveController.class);

    @Autowired
    private ISyOaReceiveService syOaReceiveService;

    /**
     * 查询招待审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaReceiveApproval:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaReceive syOaReceive)
    {
        startPage();
        List<SyOaReceive> list = syOaReceiveService.selectSyOaReceiveList(syOaReceive);
        return getDataTable(list);
    }

    /**
     * 导出招待审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaReceiveApproval:export')")
    @Log(title = "招待审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaReceive syOaReceive)
    {
        List<SyOaReceive> list = syOaReceiveService.selectSyOaReceiveList(syOaReceive);
        ExcelUtil<SyOaReceive> util = new ExcelUtil<SyOaReceive>(SyOaReceive.class);
        util.exportExcel(response, list, "招待审批数据");
    }

    /**
     * 获取招待审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaReceiveApproval:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaReceiveService.selectSyOaReceiveById(id));
    }

    /**
     * 新增招待审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaReceiveApproval:add')")
    @Log(title = "招待审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaReceive syOaReceive)
    {
        return toAjax(syOaReceiveService.insertSyOaReceive(syOaReceive));
    }

    /**
     * 修改招待审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaReceiveApproval:edit')")
    @Log(title = "招待审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaReceive syOaReceive)
    {
        return toAjax(syOaReceiveService.updateSyOaReceive(syOaReceive));
    }

    /**
     * 删除招待审批
     */
    @PreAuthorize("@ss.hasPermi('module:oaReceiveApproval:remove')")
    @Log(title = "招待审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaReceiveService.deleteSyOaReceiveByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "招待审批", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaReceive syOaReceive = syOaReceiveService.selectSyOaReceiveById(id);
            syOaReceiveService.submitApply(syOaReceive);
        } catch (Exception e) {
            LOGGER.error("招待审批提交申请出错",e);
            return error("招待审批提交申请出错：" + e.getMessage());
        }
        return success();
    }
}
